package com.shop.loan.controller;

import com.shop.loan.service.EruptDataService;
import com.shop.loan.meiqia.MeiQiaUtil;
import com.shop.loan.model.common.Code;
import com.shop.loan.model.common.ResResult;
import com.shop.loan.model.entity.UserAddressBookByMybatis;
import com.shop.loan.model.entity.UserCallLogByMybatis;
import com.shop.loan.model.entity.UserContactByMybatis;
import com.shop.loan.model.vo.AdminLoginVo;
import com.shop.loan.model.vo.LoanOrderVo;
import com.shop.loan.model.vo.OpPasswordUpdateVo;
import com.shop.loan.model.vo.UserReportVo;
import com.shop.loan.service.EruptDataService;
import com.shop.loan.service.LoanOrderService;
import com.shop.loan.service.MsgService;
import com.shop.loan.service.UserService;
import org.springframework.context.annotation.Lazy;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import xyz.erupt.core.annotation.EruptRouter;
import xyz.erupt.core.constant.EruptRestPath;
import xyz.erupt.upms.annotation.EruptMenuAuth;

import javax.annotation.Resource;

@RestController
@RequestMapping(EruptRestPath.ERUPT_API)
public class EruptController {

    @Resource
    EruptDataService eruptDataService;

    @Resource
    UserService userService;

    @Resource
    MsgService msgService;

    @Resource
    MeiQiaUtil meiQiaUtil;

    @Lazy
    @Resource
    LoanOrderService loanOrderService;

    @PostMapping("/login/getMsgCode")
    public ResResult getMsgCode(@ApiIgnore AdminLoginVo adminLoginVo) {
        return eruptDataService.getMsgCode(adminLoginVo);
    }


    @PostMapping("/login/getPicCode")
    public ResResult getPicCode(@ApiIgnore AdminLoginVo adminLoginVo) {
        return eruptDataService.getPicCode(adminLoginVo);
    }


    @EruptRouter(
            verifyType = EruptRouter.VerifyType.LOGIN
    )
    @PostMapping("/adminCode/get")
    public ResResult getAdminCode(OpPasswordUpdateVo opPasswordUpdateVo) {
        return eruptDataService.getAdminCode(opPasswordUpdateVo);
    }


    @EruptRouter(
            verifyType = EruptRouter.VerifyType.LOGIN
    )
    @PostMapping("/loanPassword/reset")
    public ResResult resetLoanPassword(OpPasswordUpdateVo opPasswordUpdateVo) {
        return eruptDataService.resetLoanPassword(opPasswordUpdateVo);
    }

    @EruptRouter(
            verifyType = EruptRouter.VerifyType.LOGIN
    )
    @PostMapping("/payPassword/reset")
    public ResResult resetPayPassword(OpPasswordUpdateVo opPasswordUpdateVo) {
        return eruptDataService.resetPayPassword(opPasswordUpdateVo);
    }

    @EruptMenuAuth("userDetail")
    @PostMapping("/user/detail")
    public ResResult detailByAdmin(@ApiIgnore LoanOrderVo orderVo) {
        return userService.detailByOrderId(orderVo);
    }


    @EruptMenuAuth("userDetail")
    @PostMapping("/user/getAddressBook")
    public ResResult getAddressBook(@ApiIgnore UserReportVo userReportVo) {
        return userService.getAddressBook(userReportVo);
    }

    @EruptMenuAuth("userDetail")
    @PostMapping("/user/getCallLog")
    public ResResult getCallLog(@ApiIgnore UserReportVo userReportVo) {
        return userService.getCallLog(userReportVo);
    }


    @EruptMenuAuth("userDetail")
    @PostMapping("/user/getLoginLog")
    public ResResult getLoginLog(@ApiIgnore UserReportVo userReportVo) {
        return userService.getLoginLog(userReportVo);
    }


    @EruptMenuAuth("userDetail")
    @PostMapping("/order/getLocationInfo")
    public ResResult getLocationInfo(@ApiIgnore LoanOrderVo loanOrderVo) {
        return loanOrderService.getLocationInfo(loanOrderVo);
    }

    @EruptMenuAuth("userDetail")
    @PostMapping("/order/getList")
    public ResResult getOrderListByUser(@ApiIgnore LoanOrderVo loanOrderVo) {
        return loanOrderService.getOrderListByUser(loanOrderVo);
    }

    @EruptMenuAuth("userDetail")
    @PostMapping("/black/update")
    public ResResult updateBlack(@ApiIgnore LoanOrderVo loanOrderVo) {
        return loanOrderService.updateBlack(loanOrderVo);
    }

    @EruptRouter(
            verifyType = EruptRouter.VerifyType.LOGIN
    )
    @PostMapping("/msg/hasNew")
    public ResResult hasNew() {
        return msgService.hasNew();
    }


    @EruptMenuAuth("userDetail")
    @PostMapping("/user/addContract")
    public ResResult addContract(UserContactByMybatis userContactByMybatis) {
        return userService.addContract(userContactByMybatis);
    }

    @EruptRouter(
            verifyType = EruptRouter.VerifyType.LOGIN
    )
    @PostMapping("/service/loginUrls")
    public ResResult loginUrls(UserContactByMybatis userContactByMybatis) {
        String loginUrl = meiQiaUtil.loginUrls();
        if (StringUtils.hasText(loginUrl)) {
            return new ResResult(Code.SUCCESS, loginUrl);
        }
        return new ResResult(Code.FAIL);
    }

}
